Rectangle a,b; a = new Rectangle(); b = new Rectangle();
class Rectangle { int length; int breadth; void area() { int a=length*breadth; System.out.println("Area is "+a); } void perimeter() { int p=2*(length+breadth); System.out.println("Perimeter is"+p); } } class demo { public static void main(String args[]) { rectangle a; a = new rectangle(); a.length=5; a.breadth=7; System.out.println(a.length); System.out.println(a.breadth); a.area(); a.perimeter(); } }
5 7 Area is 35 Perimeter is 24
class Circle { int R; void area() { double a=3.14*R*R; System.out.println("Area is "+a); } void circuimference() { double c=2*3.14*R; System.out.println("Circumference is"+c); } } class demo { public static void main(String args[]) { Circle a; a = new Circle(); a.R=5; System.out.println(a.R); a.area(); a.circuimference() } }
5 Area is 78.5 Circumference is 31.4